package cn.lingyangwl.agile.model.enums;

import cn.lingyangwl.framework.tool.core.CollectionUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 角色标识枚举
 */
@Getter
@AllArgsConstructor
public enum RoleEnum {
    OWNER("owner", "拥有者",  "1"),
    ADMIN("admin", "管理员", "2"),
    /**
     * 租户成员默认角色
     */
    MEMBER("member", "成员", "4"),
    ;

    /**
     * 角色编码
     */
    private final String code;
    /**
     * 名字
     */
    private final String name;

    private final String sort;

    public static boolean isAdmin(String code) {
        return Objects.equals(code, ADMIN.getCode());
    }

    public static boolean isTenantOwner(String code) {
        return Objects.equals(code, OWNER.getCode());
    }

    public static boolean isTenantOwner(List<String> codes) {
        if (CollectionUtils.isEmpty(codes)) {
            return false;
        }
        return codes.stream().anyMatch(e -> OWNER.getCode().equals(e));
    }

    public static RoleEnum ofByCode(String code) {
        return Arrays.stream(values()).filter(e -> e.code.equals(code)).findFirst().orElse(null);
    }
}
